package com.xiguthings.waka.publicUtils;

import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;

public class ClassUtils {
	/**
	 * 判断成员属性是否其中一个是有值的
	 * @param obj 对象
	 * @param outFields 排除在外的属性名称（不会判断这些属性的值是否是空）
	 * @return false--都为空，true--其中一个有值
	 * @throws Exception
	 */
	public static boolean fieldsHasValues(Object obj, Set<String> outFields) throws Exception {
		boolean flag = false;
		Set<String> outFieldSet = new HashSet<>(outFields);
		Class<?> clazz = obj.getClass();
		Field[] fields = clazz.getDeclaredFields();
		for (Field field : fields) {
			if (outFieldSet != null && outFieldSet.size() > 0 && outFieldSet.contains(field.getName())) {
				outFieldSet.remove(field.getName());
				continue;
			}
			field.setAccessible(true);
			Object value = field.get(obj);
			if (value != null) {
				flag = true;
				break;
			}
		}
		return flag;
	}

}
